<?php
require_once("./DButil.php");

$num = $_REQUEST["num"];
$newName = $_REQUEST["newName"];
$newFile = $_REQUEST["newFile"];

// echo $num,$newName,$newFile;

// powerName 不能相同
$sql="select * from t_power where powerName='{$newName}'";
if (query($sql)) {
    $result = [
        "msg" => "添加失败",
        "code" => 404,
        "success" => false
    ];
}else{
    if ($num>=10) {
        $sql1 = "insert into t_power (powerId,powerName,powerPath) values ('20{$num}','{$newName}','{$newFile}')";
    }else{
        $sql1 = "insert into t_power (powerId,powerName,powerPath) values ('200{$num}','{$newName}','{$newFile}')";
    }
    $add=update($sql1);
    if ($add) {
        $result = [
            "msg" => "添加成功",
            "code" => 200,
            "success" => true
        ];
    }else{
        $result = [
            "msg" => "添加失败",
            "code" => 400,
            "success" => false
        ];
    }
}

// var_dump($add) ;


header("Content-Type:application/json;charset=utf-8");
echo json_encode($result);
?>